package com.example.leetcode.aliTest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Stack;

public class Solution {

    public static ArrayList<Stack<Integer>> res = new ArrayList<>();
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] params = br.readLine().trim().split(" ");
        int n = Integer.parseInt(params[0]), m = Integer.parseInt(params[1]);
        dfs(n, m, 1, new Stack<Integer>());
        for (Stack<Integer> stack: res) {
            for (Integer i: stack) {
                System.out.print(i + " ");
            }
            System.out.println();
        }
    }

    private static void dfs(int n, int m, int depth, Stack<Integer> stack) {
        if (stack.size() == m) {
            res.add((Stack<Integer>)stack.clone());
            return;
        }
        for (int i = depth; i <= n; i++) {
            stack.push(i);
            dfs(n, m, i + 1, stack);;
            stack.pop();
        }
    }

}
